Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/accounts)!: make address generation more robust and add predictable address creation #22776

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Dec 5, 2024

Description

Closes: #17516


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced an address_seed field for account initialization to enhance address generation.
    • Added support for creating accounts at genesis with specified MsgInit messages.
    • Implemented transaction bundling for improved user experience and fee abstraction.
  • Bug Fixes

    • Added ErrAccountAlreadyExists to improve error handling during account creation.
  • Documentation

    • Updated README to include sections on Address Derivation, Genesis, and Bundling.
  • Tests

    • Enhanced tests for account initialization, including scenarios for existing accounts and seed usage.
    • Updated test cases to reflect changes in method signatures and parameters.

@testinginprod testinginprod requested review from a team and sontrinh16 as code owners December 5, 2024 11:39
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant modifications to the account management system within the Cosmos SDK. A new field, address_seed, is added to the MsgInit message structure, enhancing the address generation process for accounts. Additionally, several methods, including Init, have been updated to accommodate this new parameter, which allows for deterministic address creation. The changes also extend to various test files, ensuring that the new method signatures are correctly implemented and tested, alongside improvements in error handling and documentation updates.

Changes

File Change Summary
api/cosmos/accounts/v1/tx.pulsar.go Added field address_seed []byte to MsgInit, updated methods for serialization/deserialization.
tests/integration/accounts/base_account_test.go Updated Init method call to include an additional nil parameter.
tests/integration/accounts/fixture_test.go Modified Init method call to include an additional nil parameter.
tests/integration/accounts/lockup/continous_lockup_test_suite.go Updated Init method call to include an additional nil parameter.
tests/integration/accounts/lockup/delayed_lockup_test_suite.go Modified Init method call to include an additional nil parameter.
tests/integration/accounts/lockup/periodic_lockup_test_suite.go Updated Init method call to include an additional nil parameter.
tests/integration/accounts/lockup/permanent_lockup_test_suite.go Modified Init method call to include an additional nil parameter.
tests/integration/accounts/multisig/test_suite.go Updated initAccount method to include an additional parameter in the call to Init.
tests/integration/auth/keeper/accounts_retro_compatibility_test.go Updated Init method calls to include an additional nil parameter.
tests/integration/v2/auth/accounts_retro_compatibility_test.go Modified Init method calls to include an additional nil parameter.
x/accounts/README.md Added sections on Address Derivation, Genesis, and Bundling; introduced TxExtension message.
x/accounts/errors.go Introduced new error variable ErrAccountAlreadyExists.
x/accounts/genesis_test.go Updated Init and makeAddress method signatures to include additional parameters.
x/accounts/keeper.go Updated Init, initFromMsg, and makeAddress methods to include new parameters for address generation.
x/accounts/keeper_test.go Modified Init method calls in tests to include an additional nil parameter.
x/accounts/msg_server_test.go Added AddressSeed field to v1.MsgInit and updated tests to validate its functionality.
x/accounts/proto/cosmos/accounts/v1/tx.proto Added address_seed field to MsgInit message definition.

Assessment against linked issues

Objective Addressed Explanation
Decide on address creation scheme (17516)

Possibly related PRs

  • feat(auth): support accounts from auth #21688: The changes in the main PR introduce a new field address_seed to the MsgInit message structure, which is relevant to the MsgInit message type added in this PR, enhancing the account initialization process.
  • feat(auth): allow BaseAccounts to be migrated to x/accounts #21820: This PR discusses the migration of BaseAccount types, which relates to the changes in the main PR that also involve modifications to account structures and initialization messages.
  • test: x/accounts systemtests #22320: The new test function TestAccountsMigration in this PR directly tests the migration of accounts, which is closely related to the changes in the main PR that introduce new fields and methods for account initialization and management.
  • test(integration): port x/slashing tests to server v2 #22754: The changes in this PR focus on porting tests to server v2, which aligns with the main PR's updates to account management and initialization processes, ensuring compatibility with the latest version of the SDK.
  • ci: run runtime/v2 tests in CI #22769: This PR adds a CI job for runtime/v2 tests, which is relevant as the main PR introduces changes that may affect how tests are structured and executed in the context of account management.
  • chore: clean-up main #22787: The cleanup of legacy components in this PR is related to the main PR's focus on enhancing the account management system, ensuring that the codebase is streamlined and up-to-date with the latest practices.

Suggested labels

C:x/accounts/lockup, C:x/accounts/multisig

Suggested reviewers

  • tac0turtle
  • sontrinh16
  • akhilkumarpilli
  • testinginprod

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Dec 5, 2024

@testinginprod your pull request is missing a changelog!

@testinginprod testinginprod added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (11)
tests/integration/accounts/base_account_test.go (2)

35-35: Consider adding test cases for non-nil address seed.

The test only covers the case where addressSeed is nil. Consider adding test cases with non-nil values to verify the predictable address creation functionality.


Line range hint 41-42: TODO comment needs addressing.

The TODO comment indicates a potential issue with account existence checks in x/auth. This should be tracked and addressed.

Would you like me to create a GitHub issue to track this TODO item?

x/accounts/genesis_test.go (1)

22-22: Consider consolidating duplicate Init calls.

Both Init calls have identical parameters except for subsequent operations. Consider using a test helper function to reduce code duplication.

func initTestAccount(t *testing.T, k Keeper, ctx Context, sender []byte) ([]byte, error) {
    _, addr, err := k.Init(ctx, testAccountType, sender, &types.Empty{}, nil, nil)
    require.NoError(t, err)
    return addr, err
}

Also applies to: 28-28

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (2)

33-33: Add test cases for address seed functionality.

The test should include cases verifying that the permanent locking account works correctly with address seeds for predictable address creation.


Line range hint 42-55: Consider parameterizing error test cases.

The error test cases could be structured as a table-driven test to make it easier to add more test cases in the future.

func TestErrorCases(t *testing.T) {
    testCases := []struct {
        name    string
        msg     sdk.Msg
        wantErr bool
    }{
        {
            name: "wrong sender",
            msg: &types.MsgSend{
                Sender:    addr,
                ToAddress: addr,
                Amount:    sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))},
            },
            wantErr: true,
        },
        // Add more test cases here
    }
    // ... test execution
}
tests/integration/auth/keeper/accounts_retro_compatibility_test.go (1)

135-138: Improve test documentation for account number expectations

The test initializes two accounts but lacks clear documentation about the expected account numbers and why they start from a specific number.

Add a comment explaining:

  • Why account numbers start from a specific value
  • The relationship between account numbers and genesis accounts
x/accounts/proto/cosmos/accounts/v1/tx.proto (1)

42-44: Enhance address_seed field documentation

While the current documentation explains the basic purpose, it should provide more details about:

  • Expected format and constraints of the seed
  • Security implications
  • Whether the seed can be reused

Consider expanding the documentation to include:

  // address_seed can be used to deterministically create the address of the account.
  // If not present the address will be generated based on its associated account number.
+ // The seed must be a unique value to prevent address collisions.
+ // Format: Raw bytes with recommended length of 32 bytes for security.
+ // Security: Seeds should be generated using a cryptographically secure random number generator.
tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

102-102: Consider adding test cases for address generation

Similar to the v1 tests, this file should include test cases for the new address_seed functionality.

Consider adding test cases in a new test function TestAccountAddressGeneration to verify:

  • Deterministic address generation with seeds
  • Default address generation behavior
  • Address uniqueness guarantees
tests/integration/accounts/fixture_test.go (1)

188-188: Enhance test fixture to support address seed testing.

The test fixture could be improved to support testing different address seed scenarios. Consider adding a parameter to initFixture that allows tests to specify different address seeds.

-func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstractionv1.MsgAuthenticate) (*account_abstractionv1.MsgAuthenticateResponse, error)) *fixture {
+func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstractionv1.MsgAuthenticate) (*account_abstractionv1.MsgAuthenticateResponse, error), addressSeed []byte) *fixture {
     // ... existing code ...
-    _, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil, nil)
+    _, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil, addressSeed)
tests/integration/accounts/lockup/continous_lockup_test_suite.go (1)

37-37: Improve time-based test robustness.

While the test covers time-based locking functionality, it uses real time (time.Now()). Consider using a fixed timestamp to make tests more deterministic.

-    currentTime := time.Now()
+    currentTime := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)

Additionally, consider adding test cases for address seed functionality to ensure predictable address generation works as expected.

x/accounts/README.md (1)

511-511: Add blank line before heading.

According to markdown standards, headings should be surrounded by blank lines for better readability.

Apply this diff:

-### Method 1: Using Address Seeds
+
+### Method 1: Using Address Seeds
🧰 Tools
🪛 Markdownlint (0.35.0)

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66c593f and cb32a73.

⛔ Files ignored due to path filters (1)
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (17)
  • api/cosmos/accounts/v1/tx.pulsar.go (16 hunks)
  • tests/integration/accounts/base_account_test.go (1 hunks)
  • tests/integration/accounts/fixture_test.go (1 hunks)
  • tests/integration/accounts/lockup/continous_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/multisig/test_suite.go (1 hunks)
  • tests/integration/auth/keeper/accounts_retro_compatibility_test.go (2 hunks)
  • tests/integration/v2/auth/accounts_retro_compatibility_test.go (2 hunks)
  • x/accounts/README.md (1 hunks)
  • x/accounts/errors.go (1 hunks)
  • x/accounts/genesis_test.go (2 hunks)
  • x/accounts/keeper.go (4 hunks)
  • x/accounts/keeper_test.go (4 hunks)
  • x/accounts/msg_server_test.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
x/accounts/errors.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/accounts/msg_server_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/fixture_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/multisig/test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/auth/keeper/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/base_account_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/auth/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/delayed_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/continous_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/keeper_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

api/cosmos/accounts/v1/tx.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/accounts/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

🪛 Markdownlint (0.35.0)
x/accounts/README.md

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (17)
x/accounts/keeper.go (4)

159-159: Proper error handling after calling makeAddress

Good job handling the error returned by makeAddress. This ensures robust error handling in the account initialization process.


184-184: Consistent use of AddressSeed in initFromMsg

Passing initMsg.AddressSeed to the Init method maintains consistency in address generation and ensures that the seed is utilized properly.


203-210: Prevent re-initialization of existing accounts

The added existence check for accounts effectively prevents initializing an account that already exists, improving the robustness of the account management.


320-339: Verify the security of the new address generation logic

The makeAddress function now incorporates creator, accNum, and addressSeed to generate addresses. Ensure that this method securely prevents address collisions and squatting.

Run the following script to check for address collisions with different addressSeed values:

✅ Verification successful

Let me analyze the code further by checking for any existing test cases or similar address generation implementations.


Let me check the implementation details and any related tests specifically in the accounts module.


Let me check for any existing tests or implementations specifically related to address generation and collision prevention.


Based on the code analysis, I can now provide a final response about the security of the address generation logic.

Address generation implementation is secure against collisions and squatting

The makeAddress implementation provides strong security guarantees through:

  • Unique address derivation by combining creator address with either:
    • A unique account number (auto-incrementing)
    • Or a custom address seed
  • Front-running prevention by incorporating the creator's address
  • Collision prevention through SHA-256 hashing of the combined ModuleName + creator + seed components

The implementation ensures that:

  1. Each address is unique due to the incrementing account number
  2. Only the creator can generate a specific address
  3. Even with custom address seeds, the creator's address is still required
  4. The 256-bit hash space makes collisions cryptographically improbable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that different address seeds produce unique addresses.

# Simulate address generation with different seeds.
seeds=("seed1" "seed2" "seed3")
creator="creator_address_in_hex"

addresses=()

for seed in "${seeds[@]}"; do
  # Replace this with the actual address generation logic or a call to the relevant function.
  addr=$(echo -n "${ModuleName}${creator}${seed}" | sha256sum | awk '{print $1}')
  addresses+=("$addr")
done

# Check for duplicates.
if [ "$(printf '%s\n' "${addresses[@]}" | sort | uniq -d)" ]; then
  echo "Address collision detected."
else
  echo "No address collisions detected."
fi

Length of output: 908


Script:

#!/bin/bash
# Search for test cases related to makeAddress function
rg -A 5 "TestMakeAddress|makeAddress.*test" 

# Look for similar address generation patterns
ast-grep --pattern 'sha256.Sum256($$$)'

# Search for any existing address collision tests
rg -i "collision.*test|duplicate.*address"

Length of output: 2698


Script:

#!/bin/bash
# Check for tests in the accounts module
rg -A 10 "func.*Test" x/accounts/

# Look for any existing address generation or validation logic
rg -A 5 "address.*generation|validate.*address" x/accounts/

# Check for any existing account creation tests
fd -t f "test" x/accounts/ --exec cat {}

Length of output: 66018


Script:

#!/bin/bash
# Look for tests related to makeAddress function
rg -A 10 "makeAddress|TestMakeAddress" x/accounts/

# Search for any address collision prevention logic
rg -A 5 "collision|duplicate.*address" x/accounts/keeper/

# Check for any address validation tests
fd -t f "test" x/accounts/keeper/ --exec cat {}

Length of output: 2866

x/accounts/errors.go (1)

13-14: Addition of ErrAccountAlreadyExists improves error handling

Defining ErrAccountAlreadyExists provides a clear and specific error when an account initialization is attempted on an existing account.

x/accounts/msg_server_test.go (4)

27-27: Include AddressSeed in MsgInit for deterministic addresses

Adding AddressSeed to the MsgInit message allows testing of deterministic address creation, enhancing test coverage.


32-47: Add subtest to verify successful execution

The "success" subtest effectively verifies that the Execute method works as expected, enhancing the reliability of the tests.


49-57: Test handling of duplicate account initialization

The test correctly checks that initializing an account with the same AddressSeed results in ErrAccountAlreadyExists, ensuring proper error handling.


59-65: Ensure account can be initialized without AddressSeed

Testing initialization without an AddressSeed confirms that the system supports accounts without a seed, maintaining flexibility.

x/accounts/keeper_test.go (1)

20-20: Update tests to match the new Init method signature

The test cases have been appropriately updated with the additional nil parameter in the Init method calls, ensuring compatibility with the updated method signature.

Also applies to: 37-37, 47-47, 73-73

tests/integration/accounts/multisig/test_suite.go (1)

88-88: Modify initAccount to include the new parameter

Adding nil as the additional argument in the Init method call aligns with the updated method signature, keeping the integration tests consistent.

tests/integration/auth/keeper/accounts_retro_compatibility_test.go (1)

77-77: 🛠️ Refactor suggestion

Add test cases for address_seed parameter

The Init call has been updated to include the new address_seed parameter, but there are no test cases verifying the deterministic address generation functionality.

Consider adding test cases to verify:

  • Address generation with address_seed
  • Address generation without address_seed (default behavior)
  • Address collision prevention
tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

162-165: LGTM! Well-documented test expectations

The test clearly documents the account number expectations and explains the relationship with genesis accounts. This is a good example of clear test documentation.

tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1)

36-36: Consider adding test cases for the new parameter.

While the nil parameter has been added to the Init call, there are no test cases verifying its behavior or impact on address generation.

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1)

49-49: LGTM! Verify the impact of the Init method signature change.

The addition of the nil parameter aligns with the updated Init method signature that now supports address seeds. The nil value indicates that the test is using the default address generation method.

✅ Verification successful

Let me generate additional verification to check the Init method signature in the codebase.


Let me try a different approach to find the Init method definition.


Let me try one more search to find the Init method in the accounts module.


All Init method calls have been properly updated with the address seed parameter

Based on the search results, I can verify that all Init method calls in the test files have been updated to include the new address seed parameter. The keeper's Init method signature in x/accounts/keeper.go shows it accepts the address seed parameter, and all test files are calling it with the correct number of arguments, including the nil value for the address seed when not specifying a custom seed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all Init method calls in test files have been updated with the new parameter
# Test: Search for Init method calls in test files to ensure consistent updates
rg -A 2 "Init\(" "tests/integration/accounts/"

Length of output: 2669


Script:

#!/bin/bash
# Search for the Init method definition to verify its signature
ast-grep --pattern 'func $_($_ Keeper) Init($$$) ($_, $_, error) {
  $$$
}'

Length of output: 77


Script:

#!/bin/bash
# Search for the Init method definition using ripgrep
rg -A 5 "^func.*Init.*Keeper" 

Length of output: 2224


Script:

#!/bin/bash
# Search for Init method in the accounts module
rg -A 5 "func.*Init" "x/accounts/"

Length of output: 77246

x/accounts/README.md (1)

499-524: LGTM! Clear and comprehensive documentation of address derivation methods.

The documentation clearly explains both address derivation methods and provides important best practices for using address seeds. The implementation details and security considerations are well documented.

🧰 Tools
🪛 Markdownlint (0.35.0)

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

api/cosmos/accounts/v1/tx.pulsar.go (1)

4328-4330: LGTM! Generated protobuf code for address seed field.

The generated code properly implements the new address_seed field in the MsgInit message, with appropriate type and documentation.

Comment on lines +151 to 154
addressSeed []byte,
) (transaction.Msg, []byte, error) {
// get the next account number
num, err := k.AccountNumber.Next(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update function comment to include the new addressSeed parameter

The comment for the Init function should be updated to describe the purpose and usage of the addressSeed parameter, following Go documentation guidelines for exported functions.

@@ -62,7 +62,7 @@ func TestGenesis(t *testing.T) {
require.Equal(t, &types.UInt64Value{Value: 20}, resp)

// check initted on genesis account
addr3, err := k.makeAddress(2)
addr3, err := k.makeAddress([]byte("sender-2"), 2, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Add test cases for address generation with non-nil seeds

Based on the implementation in keeper.go, the makeAddress function supports two modes of address generation:

  1. Using creator and account number (current test coverage)
  2. Using creator and addressSeed (untested)

Add test cases to verify the deterministic address creation with non-nil seeds to ensure both code paths work as expected.

Example locations that need attention:

  • x/accounts/genesis_test.go: Add test cases with non-nil addressSeed parameter
🔗 Analysis chain

Verify address generation with non-nil seed.

The test only covers address generation with nil seed. Consider adding test cases with non-nil seeds to verify deterministic address creation.


Let me check the implementation of makeAddress to better understand the address generation logic.


Let me try to find the implementation using ripgrep instead.


Let me check all test files to see if there are any tests using non-nil addressSeed.


Let me try one more search with a different approach.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any tests covering non-nil address seeds
rg -l "makeAddress.*nil" | while read -r file; do
    echo "=== $file ==="
    rg "makeAddress.*[^n][^i][^l]" "$file" || echo "No non-nil seed tests found"
done

Length of output: 252


Script:

#!/bin/bash
# Find the implementation of makeAddress function
ast-grep --pattern 'func $_ makeAddress($$$) {
  $$$
}'

Length of output: 57


Script:

#!/bin/bash
# Find the implementation of makeAddress function
rg -A 10 "func.*makeAddress"

Length of output: 733


Script:

#!/bin/bash
# Search for makeAddress calls in test files
fd -e test.go --exec rg -B2 -A2 "makeAddress.*\(" {} \;

Length of output: 60


Script:

#!/bin/bash
# Search for all makeAddress calls in the codebase
rg -B2 -A2 "makeAddress\(" 

Length of output: 1070

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (8)
tests/integration/accounts/base_account_test.go (1)

35-35: Document the new nil parameter's purpose

The additional nil parameter represents the address_seed option. Consider adding a comment explaining its purpose for better test clarity.

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1)

33-33: Add test cases for address seed with lockup accounts

The test suite should include cases verifying address generation behavior with different address seeds for lockup accounts. This is particularly important as lockup accounts may have special requirements for address determinism.

Consider adding the following test cases:

  1. Initialize with specific address seed
  2. Verify address consistency when using the same seed
  3. Verify address uniqueness with different seeds
tests/integration/auth/keeper/accounts_retro_compatibility_test.go (2)

77-77: Consider adding test cases for address_seed parameter

While the current test verifies backward compatibility with nil address_seed, it would be valuable to add test cases that verify the deterministic address generation behavior with non-nil address_seed values.


135-138: Add comment explaining the account number expectations

The test initializes two accounts, but the comment about account numbers starting at 4 is only present in the v2 test file. Consider adding a similar explanatory comment here for maintainability.

-	_, _, err = f.accountsKeeper.Init(f.app.Context(), "base", []byte("me"), &basev1.MsgInit{PubKey: anyPk}, nil, nil)
-	require.NoError(t, err)
-
-	_, addr, err := f.accountsKeeper.Init(f.app.Context(), "base", []byte("me"), &basev1.MsgInit{PubKey: anyPk}, nil, nil)
+	// Account number should start with 1 since we're initializing the first account
+	_, _, err = f.accountsKeeper.Init(f.app.Context(), "base", []byte("me"), &basev1.MsgInit{PubKey: anyPk}, nil, nil)
+	require.NoError(t, err)
+
+	// Second account should have account number 2
+	_, addr, err := f.accountsKeeper.Init(f.app.Context(), "base", []byte("me"), &basev1.MsgInit{PubKey: anyPk}, nil, nil)
tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

102-102: LGTM! Consider adding address_seed test cases

Similar to the v1 test file, consider adding test cases that verify deterministic address generation with non-nil address_seed values.

tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1)

36-36: Document the purpose of the new nil parameter

The addition of a nil parameter to the Init call suggests support for optional configuration. Consider adding a comment explaining its purpose and potential future use.

tests/integration/accounts/fixture_test.go (1)

188-188: Consider adding error validation for the Init parameters

While the nil parameter addition maintains consistency, consider adding validation for future non-nil parameters to ensure robust error handling in the test fixture.

tests/integration/accounts/lockup/continous_lockup_test_suite.go (1)

37-37: Consider adding edge case tests for time boundaries

While the test coverage is good, consider adding edge cases for time boundaries (e.g., exactly at start time, one second before end time) to ensure robust handling of the continuous locking mechanism.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66c593f and cb32a73.

⛔ Files ignored due to path filters (1)
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (17)
  • api/cosmos/accounts/v1/tx.pulsar.go (16 hunks)
  • tests/integration/accounts/base_account_test.go (1 hunks)
  • tests/integration/accounts/fixture_test.go (1 hunks)
  • tests/integration/accounts/lockup/continous_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/multisig/test_suite.go (1 hunks)
  • tests/integration/auth/keeper/accounts_retro_compatibility_test.go (2 hunks)
  • tests/integration/v2/auth/accounts_retro_compatibility_test.go (2 hunks)
  • x/accounts/README.md (1 hunks)
  • x/accounts/errors.go (1 hunks)
  • x/accounts/genesis_test.go (2 hunks)
  • x/accounts/keeper.go (4 hunks)
  • x/accounts/keeper_test.go (4 hunks)
  • x/accounts/msg_server_test.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
x/accounts/errors.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/msg_server_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/continous_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/fixture_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/keeper_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/base_account_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/auth/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/auth/keeper/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/delayed_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/multisig/test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/accounts/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/v1/tx.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 Markdownlint (0.35.0)
x/accounts/README.md

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (23)
x/accounts/keeper.go (5)

151-151: Addition of 'addressSeed' parameter to 'Init' enhances functionality

The introduction of the addressSeed []byte parameter in the Init function allows for more robust and predictable address creation, aligning with the PR objectives.


159-159: Passing 'addressSeed' to 'makeAddress' ensures consistent address generation

Updating the call to k.makeAddress to include addressSeed correctly propagates the seed value for address creation.


184-184: Correctly forwarding 'AddressSeed' in 'initFromMsg'

The Init method within initFromMsg now properly includes initMsg.AddressSeed, ensuring that the seed is used during account initialization.


203-211: Proper handling of duplicate account initialization

The addition of the account existence check prevents duplicate accounts by returning ErrAccountAlreadyExists if the account already exists. This improves error handling and system robustness.


320-339: Address generation logic in 'makeAddress' is secure and robust

The makeAddress function correctly incorporates both creator and addressSeed to generate a unique address using SHA-256. This approach mitigates address squatting and ensures predictability when addressSeed is provided.

x/accounts/errors.go (1)

13-14: Definition of 'ErrAccountAlreadyExists' aligns with error handling practices

Adding ErrAccountAlreadyExists with an appropriate error code and message conforms to the existing error pattern and aids in clear error communication.

x/accounts/msg_server_test.go (4)

27-27: Inclusion of 'AddressSeed' in test initialization reflects new functionality

The test case now includes the AddressSeed parameter, properly testing the new address generation feature.


32-47: 'success' subtest effectively verifies account initialization and execution

Organizing the test into a subtest improves clarity, and the execution logic correctly tests the account's ability to handle messages after initialization.


49-57: Duplicate account initialization test ensures error is correctly returned

The new subtest checks that initializing an account with the same AddressSeed leads to ErrAccountAlreadyExists, validating the duplicate prevention logic.


59-65: Test confirms successful initialization without an 'AddressSeed'

By testing initialization without providing an AddressSeed, this subtest verifies that the seed is truly optional and that the default behavior remains functional.

x/accounts/keeper_test.go (4)

20-20: Tests updated to match new 'Init' method signature

Including nil as the additional parameter ensures that the tests align with the updated Init function, maintaining test integrity.


37-37: 'unknown account type' test correctly adapts to signature change

The test appropriately reflects the method signature update, continuing to validate error handling for invalid account types.


47-47: Account initialization in 'TestKeeper_Execute' updated properly

The addition of nil aligns the test with the new Init method parameters, ensuring accurate testing of account execution.


73-73: 'TestKeeper_Query' initialization updated to include new parameter

The test setup now correctly includes the additional nil parameter, keeping the query tests consistent with the updated method signature.

tests/integration/accounts/multisig/test_suite.go (1)

88-88: Multisig account initialization updated to include 'addressSeed' parameter

The initAccount function now passes nil for the addressSeed, ensuring compatibility with the updated Init method and maintaining the existing test behavior.

x/accounts/genesis_test.go (2)

22-22: Consider testing with non-nil address seed

Both Init calls use nil for the address seed. Consider adding test cases with specific address seeds to verify deterministic address generation.

Also applies to: 28-28


65-65: Verify makeAddress behavior with different seeds

The makeAddress call includes new parameters for sender and seed. Consider adding test cases to verify address uniqueness with different combinations of sender and seed values.

x/accounts/proto/cosmos/accounts/v1/tx.proto (1)

42-44: LGTM! Well-documented field addition

The new address_seed field is properly documented and follows protobuf best practices. The documentation clearly explains both the purpose and the default behavior.

tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

162-165: LGTM! Well-documented account initialization

The comment clearly explains the expected account numbers and why they start at 4 (due to fee_collector, bonded_tokens_pool, not_bonded_tokens_pool, and one genesis account).

tests/integration/accounts/lockup/continous_lockup_test_suite.go (1)

Line range hint 1-200: Verify consistent behavior across all account types

The changes to the Init method signature should be verified across all account types to ensure consistent behavior.

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1)

49-49: LGTM! Test coverage maintained with signature update.

The addition of the nil parameter to the Init method call correctly adapts the test to the new method signature that supports optional address seeds, while preserving the original test coverage.

✅ Verification successful

Test coverage maintained with signature update

The verification confirms that the Init method call in the test correctly adapts to the new method signature by passing nil as the AddressSeed parameter. The test maintains proper coverage of the periodic locking account initialization by providing all required parameters:

  • Owner address
  • Start time
  • Locking periods
  • Initial funds (1500 stake)
  • Address seed (nil)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify test coverage for the Init method with address seed parameter
ast-grep --pattern 'Init($_, $_, $_, $_, $_)' 

Length of output: 47


Script:

#!/bin/bash
# Let's first check the Init method signature and its usages
rg "Init.*\(" --type go -A 2

Length of output: 68758


Script:

#!/bin/bash
# Let's check the Init method implementation in the lockup test suite
rg -A 5 "Init.*\(" tests/integration/accounts/lockup/periodic_lockup_test_suite.go

Length of output: 383


Script:

#!/bin/bash
# Let's check the MsgInitPeriodicLockingAccount type definition to understand its parameters
rg -A 10 "type MsgInitPeriodicLockingAccount struct" -g "*.go"

Length of output: 2300

x/accounts/README.md (1)

499-524: Documentation is comprehensive but needs formatting fixes.

The content clearly explains address derivation methods and best practices. However, the markdown headings should be surrounded by blank lines for better readability.

Apply these formatting changes:

 ## Address Derivation
+
 The x/accounts module offers two methods for deriving addresses...
+
 ### Method 1: Using Address Seeds
+
 When creating an account via `MsgInit`...
+
 ### Method 2: Using Account Numbers
+
 If no address seed is provided...
+
 ### Address Seed Best Practices
+
 1. Address seeds must be unique per creator...
✅ Verification successful

Documentation matches implementation, but formatting changes are needed.

The address derivation implementation in x/accounts/keeper.go matches the documented behavior:

  1. For address seed method:
seed = append(creator, addressSeed...)
moduleAndSeed := append([]byte(ModuleName), seed...)
addr := sha256.Sum256(moduleAndSeed)
  1. For account number method:
seed = append(creator, binary.BigEndian.AppendUint64(nil, accNum)...)
moduleAndSeed := append([]byte(ModuleName), seed...)
addr := sha256.Sum256(moduleAndSeed)

The suggested markdown formatting changes will improve readability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the documented address derivation matches implementation
ast-grep --pattern 'func makeAddress($creator, $seed) {
  $$$
  sha256($$$)
  $$$
}'

Length of output: 86


Script:

#!/bin/bash
# Search for address derivation implementation using ripgrep
rg -A 10 "func.*[Mm]akeAddress|func.*[Dd]eriveAddress" --type go

# Also search for any SHA256 related code
rg -A 5 "sha256|SHA256" --type go

Length of output: 54917

🧰 Tools
🪛 Markdownlint (0.35.0)

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

api/cosmos/accounts/v1/tx.pulsar.go (1)

Line range hint 77-87: LGTM! Generated protobuf code looks correct.

The protobuf code generation for the new address_seed field appears to be complete and correct, with all necessary methods and field descriptors properly generated.

Also applies to: 179-184, 208-209, 234-235, 267-269, 300-301, 337-338, 362-363, 4328-4330, 4381-4386

✅ Verification successful

Let me gather more information about the protobuf definitions to verify field numbers.


Let me try to find the proto file first.


Protobuf field generation for address_seed is correctly implemented

The generated code in tx.pulsar.go correctly reflects the protobuf definition in tx.proto. The address_seed field is properly defined as field number 5 in the proto file and is correctly included in the generated field descriptors, maintaining proper field ordering and compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify protobuf field numbers are sequential and there are no conflicts
rg -A 1 'fd_MsgInit_[a-z_]+ =' | sort

Length of output: 1551


Script:

#!/bin/bash
# Check the proto file for field numbers and definitions
rg -A 10 'message MsgInit' api/cosmos/accounts/v1/tx.proto

Length of output: 132


Script:

#!/bin/bash
# Find the proto file containing MsgInit message
fd -e proto -x rg -l 'message MsgInit'

Length of output: 421


Script:

#!/bin/bash
# Check the main tx.proto file for MsgInit field definitions
rg -A 10 'message MsgInit' ./x/accounts/proto/cosmos/accounts/v1/tx.proto

Length of output: 919


Script:

#!/bin/bash
# Get the full MsgInit message definition to see all fields including address_seed
rg -B 5 -A 15 'message MsgInit' ./x/accounts/proto/cosmos/accounts/v1/tx.proto

Length of output: 1778

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (10)
x/accounts/keeper.go (2)

151-151: Add documentation for the new addressSeed parameter in Init.

The Init method now includes the addressSeed parameter, but the method's documentation doesn't mention it. Updating the documentation will improve clarity for other developers using this method.


320-339: Clarify the address generation logic in makeAddress.

While the makeAddress function effectively generates addresses using the creator, addressSeed, and ModuleName, adding comments to explain how this helps prevent address squatting and ensures predictability would enhance code readability and maintainability.

x/accounts/msg_server_test.go (1)

32-32: Use descriptive names for test cases.

Consider renaming the sub-test "success" to something more descriptive like "execute message successfully" to improve test readability.

x/accounts/keeper_test.go (1)

20-22: Improve readability when passing multiple nil parameters.

Passing multiple nil parameters to the Init function can make the code less readable. Consider assigning these nil values to variables with descriptive names to clarify their purpose in the function call.

Also applies to: 37-38, 47-49, 73-75

tests/integration/accounts/multisig/test_suite.go (1)

88-88: Ensure clarity when passing nil parameters in function calls.

In the initAccount method, passing nil directly as an argument to s.app.AccountsKeeper.Init may reduce code clarity. Consider using a named variable or adding a comment to explain what the nil represents.

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1)

32-34: Consider security implications of predictable addresses

The combination of lockup accounts and predictable address generation requires careful consideration of potential security implications.

Recommendations:

  1. Document the interaction between address prediction and lockup mechanics
  2. Consider rate limiting or additional validation for address generation
  3. Add checks to prevent address grinding attacks
tests/integration/auth/keeper/accounts_retro_compatibility_test.go (1)

135-138: Update comment accuracy regarding account numbers

The test initializes two accounts, but the comment about account numbers could be more precise.

Consider updating the comment to:

-  // we init two accounts to have account num not be zero.
+  // Initialize two accounts. The second account will have account number 1
+  // as it's created after the first account.
tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

162-165: Enhance account number documentation

While the comment about account numbers is more detailed than in v1, it could be even clearer.

Consider updating the comment to:

-  // we init two accounts. Account number should start with 4
-  // since the first three accounts are fee_collector, bonded_tokens_pool, not_bonded_tokens_pool
-  // generated by init genesis plus one more genesis account, which make the current account number 4.
+  // Initialize two accounts sequentially. Account numbers will be 4 and 5 because:
+  // 1. Three system accounts (fee_collector, bonded_tokens_pool, not_bonded_tokens_pool) are created at genesis
+  // 2. One additional genesis account exists
+  // Therefore, the first account created here will be #4, and the second will be #5
tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1)

36-36: LGTM! Consider documenting the nil parameter.

The addition of the nil parameter aligns with the new address generation feature. Consider adding a comment explaining that this parameter is for address_seed to improve code readability.

-	}, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil)
+	}, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil /* address_seed */)
tests/integration/accounts/lockup/continous_lockup_test_suite.go (1)

37-37: LGTM! Consider documenting the nil parameter.

The addition of the nil parameter aligns with the new address generation feature. Consider adding a comment explaining that this parameter is for address_seed to improve code readability.

-	}, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil)
+	}, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil /* address_seed */)
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66c593f and cb32a73.

⛔ Files ignored due to path filters (1)
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (17)
  • api/cosmos/accounts/v1/tx.pulsar.go (16 hunks)
  • tests/integration/accounts/base_account_test.go (1 hunks)
  • tests/integration/accounts/fixture_test.go (1 hunks)
  • tests/integration/accounts/lockup/continous_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/delayed_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1 hunks)
  • tests/integration/accounts/multisig/test_suite.go (1 hunks)
  • tests/integration/auth/keeper/accounts_retro_compatibility_test.go (2 hunks)
  • tests/integration/v2/auth/accounts_retro_compatibility_test.go (2 hunks)
  • x/accounts/README.md (1 hunks)
  • x/accounts/errors.go (1 hunks)
  • x/accounts/genesis_test.go (2 hunks)
  • x/accounts/keeper.go (4 hunks)
  • x/accounts/keeper_test.go (4 hunks)
  • x/accounts/msg_server_test.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
x/accounts/errors.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/integration/accounts/multisig/test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/fixture_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/msg_server_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/auth/keeper/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/accounts/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/keeper_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/base_account_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/auth/accounts_retro_compatibility_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/accounts/lockup/continous_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

api/cosmos/accounts/v1/tx.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/integration/accounts/lockup/delayed_lockup_test_suite.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 Markdownlint (0.35.0)
x/accounts/README.md

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (11)
x/accounts/errors.go (1)

13-14: LGTM!

The new error ErrAccountAlreadyExists is appropriately defined and enhances error handling for account initialization.

x/accounts/msg_server_test.go (1)

27-65: Good test coverage for the new AddressSeed functionality.

The added tests in TestMsgServer sufficiently cover the new scenarios related to AddressSeed, including successful initialization, handling duplicate initializations, and initialization without a seed.

tests/integration/accounts/base_account_test.go (1)

35-35: 🛠️ Refactor suggestion

Add test cases for address generation feature

While the nil parameter has been added for the new address generation feature, there are no test cases validating the behavior with non-nil address seeds.

Consider adding test cases to validate:

  1. Address generation with specific seeds
  2. Address collision prevention
  3. Deterministic address creation
x/accounts/genesis_test.go (1)

65-65: Verify address generation determinism in genesis

The new address generation parameters in makeAddress should be tested for determinism across genesis export and import cycles.

✅ Verification successful

Let me gather more information about the address generation tests.


Let me check the keeper implementation to understand the address generation logic.


Address generation determinism is properly implemented and tested

The genesis test already verifies address determinism by:

  • Exporting and importing state with multiple accounts
  • Verifying that addr3 generated with makeAddress matches the imported genesis account
  • Confirming the account state is preserved across export/import cycles

The makeAddress implementation ensures deterministic address generation by:

  • Using a consistent seed generation from creator and account number when no address seed is provided
  • Using creator + address seed when a custom seed is provided
  • Prefixing with module name for namespace isolation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any existing determinism tests
rg -A 5 "deterministic.*address" 

Length of output: 4302


Script:

#!/bin/bash
# Check the genesis test implementation
cat x/accounts/genesis_test.go

# Check the makeAddress implementation
ast-grep --pattern 'func $_ makeAddress($$$) {
  $$$
}'

Length of output: 4357


Script:

#!/bin/bash
# Check the keeper implementation for makeAddress
rg -A 10 "func.*makeAddress" x/accounts/keeper.go

Length of output: 523

tests/integration/accounts/lockup/permanent_lockup_test_suite.go (1)

33-33: 🛠️ Refactor suggestion

Verify address generation for specialized account types

The lockup account initialization should be tested with address seeds to ensure compatibility with the new address generation mechanism.

Add test cases to verify:

  1. Address generation with seeds for locked accounts
  2. Address uniqueness across different lockup types
  3. Deterministic address creation for specialized accounts
tests/integration/auth/keeper/accounts_retro_compatibility_test.go (1)

77-77: LGTM: Init method signature updated correctly

The additional nil parameter for address_seed is properly added, maintaining backward compatibility while supporting the new address generation feature.

x/accounts/proto/cosmos/accounts/v1/tx.proto (1)

42-44: LGTM: Well-documented address_seed field addition

The new field is properly documented and follows proto3 conventions. The comment clearly explains both the purpose and the fallback behavior.

tests/integration/v2/auth/accounts_retro_compatibility_test.go (1)

102-102: LGTM: Init method signature updated correctly

The additional nil parameter for address_seed is properly added, maintaining consistency with the new interface.

tests/integration/accounts/lockup/periodic_lockup_test_suite.go (1)

49-49: LGTM: API adaptation for address seed support

The change correctly adapts to the new Init method signature by passing nil for the optional address seed parameter, maintaining the existing test behavior.

x/accounts/README.md (1)

499-524: LGTM: Clear and comprehensive documentation on address derivation

The documentation effectively explains both address derivation methods, their formulas, and provides valuable best practices for using address seeds. The content is well-structured and helps developers understand how to implement deterministic address generation.

🧰 Tools
🪛 Markdownlint (0.35.0)

511-511: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


514-514: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

api/cosmos/accounts/v1/tx.pulsar.go (1)

4328-4330: LGTM: Clean protobuf generation for address seed support

The generated code correctly implements the new address_seed field with proper protobuf tags and all necessary methods for field handling.

Comment on lines +22 to +28
_, addr1, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil, nil)
require.NoError(t, err)
_, err = k.Execute(ctx, addr1, []byte("sender"), &types.UInt64Value{Value: 10}, nil)
require.NoError(t, err)

// we set counter to 20
_, addr2, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
_, addr2, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add test cases for address seed persistence

The genesis test should verify that address seeds are correctly persisted and restored during export/import cycles.

Consider adding test cases that:

  1. Initialize accounts with specific address seeds
  2. Export genesis
  3. Import genesis
  4. Verify address reconstruction

@@ -185,7 +185,7 @@ func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstract
banktypes.RegisterMsgServer(router, bankkeeper.NewMsgServerImpl(bankKeeper))

// init account
_, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil)
_, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove redundant nil parameter.

The Init method call includes two nil parameters, which appears to be redundant. One nil parameter should be sufficient for the address_seed.

-	_, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil, nil)
+	_, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil)

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@julienrbrt
Copy link
Member

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
tests/integration/accounts/wiring_test.go (1)

Line range hint 1-70: Test coverage assessment: Comprehensive integration testing

The test provides good coverage of component integration:

  • Verifies gas consumption before and after operations
  • Tests chain ID propagation via header service
  • Validates address encoding/decoding
  • Confirms correct fund transfers and balance updates
  • Includes proper error handling and assertions

However, consider adding test cases for:

  1. Error scenarios with the new Init parameters
  2. Edge cases in address generation
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cb32a73 and c81934e.

📒 Files selected for processing (1)
  • tests/integration/accounts/wiring_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/integration/accounts/wiring_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (1)
tests/integration/accounts/wiring_test.go (1)

31-31: Verify the purpose of new nil parameters

The test passes nil values for the new parameters in Init. Consider adding test cases that exercise these parameters with non-nil values to ensure robust testing of the new address generation functionality.

Let's check how these parameters are used in other test files:

@julienrbrt julienrbrt added this pull request to the merge queue Dec 9, 2024
Merged via the queue into main with commit ecd53f8 Dec 9, 2024
77 of 78 checks passed
@julienrbrt julienrbrt deleted the tip/accounts/deterministic_accounts branch December 9, 2024 15:18
mergify bot pushed a commit that referenced this pull request Dec 9, 2024
…table address creation (#22776)

Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit ecd53f8)

# Conflicts:
#	api/cosmos/accounts/v1/tx.pulsar.go
#	tests/integration/v2/auth/accounts_retro_compatibility_test.go
julienrbrt added a commit that referenced this pull request Dec 9, 2024
…table address creation (backport #22776) (#22805)

Co-authored-by: testinginprod <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/accounts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(accounts): Decide on address creation scheme
3 participants